package com.ncmem.up6.storage;

import com.ncmem.up6.PathTool;
import com.ncmem.up6.model.FileInf;
import org.apache.tomcat.util.http.fileupload.FileItem;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class DfsBlockWriter extends FileBlockWriter{

    public DfsBlockWriter() {
        this.storage= StorageType.FastDFS;
    }

    public String make(FileInf file)
    {
        String fileID="";
        String ext = PathTool.getExtention(file.pathSvr);
        byte[] buf = new byte[0];
        fileID = FastDFSTool.upload(buf, ext);
        return fileID;
    }

    public String write(FileInf file, ByteArrayOutputStream ostm)
    {
        byte[] data = ostm.toByteArray();
        if(FastDFSTool.write(file.pathSvr, data)) return "ok";
        return "";
    }
}
